home *** CD-ROM | disk | FTP | other *** search
- Path: csun.edu!kc44097
- From: kc44097@csun.edu (chen)
- Newsgroups: comp.lang.c
- Subject: About union
- Date: 10 Apr 1996 06:06:40 GMT
- Organization: California State University, Northridge
- Message-ID: <4kfj5g$24n@dewey.csun.edu>
- NNTP-Posting-Host: huey.csun.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
-
- I read the program below from a book and do not know how it
- works,can anyone give me some advice ?
-
- Please e-mail me : kc44097@huey.csun.edu
- Thankx !
- -----------------------------------------------------
-
-
- #include <stdio.h>
-
- union {
- int integer;
- float floating;
- } myUnion;
-
-
- main()
- {
-
- myUnion.integer = 1109917697;
-
- (void) printf("The value of integer is %d\n", myUnion.integer);
- (void) printf("The value of floating is %f\n\n", myUnion.floating);
-
- (void) printf("The value of \"cast\" is %f\n", (float) myUnion.integer);
- (void) printf("The value of \"magic\" is %f\n\n", myUnion.integer);
-
- (void) printf("The meaning of life ``%d''\n", (int) myUnion.floating);
- return (0);
- }
-
-
- // The output are :
-
- The value of integer is 1
- The value of floating is 0.000000
-
- The value of "cast" is 1.000000
- The value of "magic" is 0.000000
-
- The meaning of life "0"
-